

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>roster_core.core_helpers &mdash; Roster Core v0.17 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     'v0.17',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Roster Core v0.17 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Roster Core v0.17 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for roster_core.core_helpers</h1><div class="highlight"><pre>
<span class="c">#!/usr/bin/python</span>

<span class="c"># Copyright (c) 2009, Purdue University</span>
<span class="c"># All rights reserved.</span>
<span class="c"># </span>
<span class="c"># Redistribution and use in source and binary forms, with or without</span>
<span class="c"># modification, are permitted provided that the following conditions are met:</span>
<span class="c"># </span>
<span class="c"># Redistributions of source code must retain the above copyright notice, this</span>
<span class="c"># list of conditions and the following disclaimer.</span>
<span class="c">#</span>
<span class="c"># Redistributions in binary form must reproduce the above copyright notice, this</span>
<span class="c"># list of conditions and the following disclaimer in the documentation and/or</span>
<span class="c"># other materials provided with the distribution.</span>
<span class="c"># </span>
<span class="c"># Neither the name of the Purdue University nor the names of its contributors</span>
<span class="c"># may be used to endorse or promote products derived from this software without</span>
<span class="c"># specific prior written permission.</span>
<span class="c"># </span>
<span class="c"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;</span>
<span class="c"># AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span class="c"># IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<span class="c"># DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE</span>
<span class="c"># FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<span class="c"># DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR</span>
<span class="c"># SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</span>
<span class="c"># CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,</span>
<span class="c"># OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<span class="c"># OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>

<span class="sd">&quot;&quot;&quot;Core helper functions.&quot;&quot;&quot;</span>

<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">&#39;Copyright (C) 2009, Purdue University&#39;</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s">&#39;BSD&#39;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s">&#39;#TRUNK#&#39;</span>


<span class="kn">import</span> <span class="nn">constants</span>
<span class="kn">import</span> <span class="nn">errors</span>
<span class="kn">import</span> <span class="nn">helpers_lib</span>

<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">dns.zone</span>
<span class="kn">import</span> <span class="nn">IPy</span>

<div class="viewcode-block" id="CoreHelpers"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers">[docs]</a><span class="k">class</span> <span class="nc">CoreHelpers</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot;Library of helper functions that extend the core functions.&quot;&quot;&quot;</span>
  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">core_instance</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Sets up core instance</span>

<span class="sd">    Inputs:</span>
<span class="sd">       core_instance: instance of RosterCore</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span> <span class="o">=</span> <span class="n">core_instance</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span> <span class="o">=</span> <span class="n">core_instance</span><span class="o">.</span><span class="n">db_instance</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span> <span class="o">=</span> <span class="n">core_instance</span><span class="o">.</span><span class="n">user_instance</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span> <span class="o">=</span> <span class="n">core_instance</span><span class="o">.</span><span class="n">log_instance</span>

  <span class="c">### These functions just expose helpers_lib functions for the </span>
  <span class="c">### XML-RPC server. For doc strings see helpers_lib</span>
<div class="viewcode-block" id="CoreHelpers.ListGroupPermissions"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListGroupPermissions">[docs]</a>  <span class="k">def</span> <span class="nf">ListGroupPermissions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">data_validation_instance</span><span class="o">.</span><span class="n">ListGroupPermissions</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ReverseIP"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ReverseIP">[docs]</a>  <span class="k">def</span> <span class="nf">ReverseIP</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ip_address</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">ReverseIP</span><span class="p">(</span><span class="n">ip_address</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.UnReverseIP"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.UnReverseIP">[docs]</a>  <span class="k">def</span> <span class="nf">UnReverseIP</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ip_address</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnReverseIP</span><span class="p">(</span><span class="n">ip_address</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.CIDRExpand"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.CIDRExpand">[docs]</a>  <span class="k">def</span> <span class="nf">CIDRExpand</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">,</span> <span class="n">begin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">CIDRExpand</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">,</span> <span class="n">begin</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ExpandIPV6"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ExpandIPV6">[docs]</a>  <span class="k">def</span> <span class="nf">ExpandIPV6</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ip_address</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">ExpandIPV6</span><span class="p">(</span><span class="n">ip_address</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.GetViewsByUser"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.GetViewsByUser">[docs]</a>  <span class="k">def</span> <span class="nf">GetViewsByUser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists view names available to given username</span>

<span class="sd">    Inputs:</span>
<span class="sd">        username: string of user name</span>

<span class="sd">    Outputs:</span>
<span class="sd">        list: list of view name strings</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="n">function_name</span><span class="p">)</span>
    <span class="n">views</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([])</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>

    <span class="n">users_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">)</span>
    <span class="n">users_dict</span><span class="p">[</span><span class="s">&#39;user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">username</span>
    <span class="n">user_group_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;user_group_assignments&#39;</span><span class="p">)</span>
    <span class="n">groups_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
    <span class="n">forward_zone_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">)</span>
    <span class="n">zones_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">joined_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
          <span class="s">&#39;users&#39;</span><span class="p">,</span> <span class="n">users_dict</span><span class="p">,</span> <span class="s">&#39;user_group_assignments&#39;</span><span class="p">,</span>
          <span class="n">user_group_assignments_dict</span><span class="p">,</span>
          <span class="s">&#39;groups&#39;</span><span class="p">,</span> <span class="n">groups_dict</span><span class="p">,</span> <span class="s">&#39;forward_zone_permissions&#39;</span><span class="p">,</span>
          <span class="n">forward_zone_permissions_dict</span><span class="p">,</span> <span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zones_dict</span><span class="p">,</span>
          <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">view_dict</span> <span class="ow">in</span> <span class="n">joined_list</span><span class="p">:</span>
      <span class="n">views</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">view_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span>
          <span class="s">&#39;_dep&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>

    <span class="k">return</span> <span class="n">views</span>
</div>
  <span class="k">def</span> <span class="nf">_FixHostname</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">host_name</span><span class="p">,</span> <span class="n">origin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Checks name and returns fqdn.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      host_name: string of host name</span>
<span class="sd">      origin: string of the zone origin</span>

<span class="sd">    Outputs:</span>
<span class="sd">      string of fully qualified domain name</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">host_name</span> <span class="o">==</span> <span class="s">u&#39;@&#39;</span> <span class="p">):</span>
      <span class="n">host_name</span> <span class="o">=</span> <span class="n">origin</span>
    <span class="k">elif</span><span class="p">(</span> <span class="ow">not</span> <span class="n">host_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span> <span class="p">):</span>
      <span class="n">host_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">host_name</span><span class="p">,</span> <span class="n">origin</span><span class="p">)</span>
    <span class="k">return</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">host_name</span><span class="p">)</span>

<div class="viewcode-block" id="CoreHelpers.AddFormattedRecords"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.AddFormattedRecords">[docs]</a>  <span class="k">def</span> <span class="nf">AddFormattedRecords</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">zone_file_string</span><span class="p">,</span>
                          <span class="n">view</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Adds records from a string of a partial zone file</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      zone_file_string: string of the file contents</span>
<span class="sd">      view: string of view name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: Amount of records added to db.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">origin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListZones</span><span class="p">(</span><span class="n">zone_name</span><span class="o">=</span><span class="n">zone_name</span><span class="p">)[</span>
          <span class="n">zone_name</span><span class="p">][</span><span class="n">view</span><span class="p">][</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span>

    <span class="n">zone</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="c">#If the file doesn&#39;t have an origin, we need to give it something</span>
    <span class="c">#otherwise dns.zone will raise an UnknownOrigin exception</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">zone_file_string</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&quot;$ORIGIN&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span> <span class="p">):</span>
      <span class="n">zone</span> <span class="o">=</span> <span class="n">dns</span><span class="o">.</span><span class="n">zone</span><span class="o">.</span><span class="n">from_text</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">zone_file_string</span><span class="p">),</span> <span class="n">check_origin</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
        <span class="n">origin</span><span class="o">=</span><span class="n">origin</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">zone</span> <span class="o">=</span> <span class="n">dns</span><span class="o">.</span><span class="n">zone</span><span class="o">.</span><span class="n">from_text</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">zone_file_string</span><span class="p">),</span> <span class="n">check_origin</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>   

    <span class="n">make_record_args_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">record_tuple</span> <span class="ow">in</span> <span class="n">zone</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
      <span class="n">record_target</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record_tuple</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

      <span class="k">for</span> <span class="n">record_set</span> <span class="ow">in</span> <span class="n">record_tuple</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">rdatasets</span><span class="p">:</span>
        <span class="n">ttl</span> <span class="o">=</span> <span class="n">record_set</span><span class="o">.</span><span class="n">ttl</span>
        <span class="k">for</span> <span class="n">record_object</span> <span class="ow">in</span> <span class="n">record_set</span><span class="o">.</span><span class="n">items</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">PTR</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;ptr&#39;</span>
            <span class="n">assignment_host</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FixHostname</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="p">),</span> <span class="n">origin</span><span class="p">)</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;assignment_host&#39;</span><span class="p">:</span> <span class="n">assignment_host</span><span class="p">}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">A</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;a&#39;</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;assignment_ip&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="p">)}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">AAAA</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;aaaa&#39;</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;assignment_ip&#39;</span><span class="p">:</span>
                                    <span class="nb">unicode</span><span class="p">(</span><span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
                                        <span class="n">record_object</span><span class="p">))</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">())}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">CNAME</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
            <span class="n">assignment_host</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FixHostname</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="p">),</span> <span class="n">origin</span><span class="p">)</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;assignment_host&#39;</span><span class="p">:</span> <span class="n">assignment_host</span><span class="p">}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">HINFO</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;hinfo&#39;</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;hardware&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="o">.</span><span class="n">cpu</span><span class="p">),</span>
                                <span class="s">u&#39;os&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="o">.</span><span class="n">os</span><span class="p">)}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">TXT</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;txt&#39;</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;quoted_text&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="p">)}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">MX</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;mx&#39;</span>
            <span class="n">mail_server</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FixHostname</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="o">.</span><span class="n">exchange</span><span class="p">),</span> <span class="n">origin</span><span class="p">)</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;priority&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">preference</span><span class="p">,</span>
                                <span class="s">u&#39;mail_server&#39;</span><span class="p">:</span> <span class="n">mail_server</span><span class="p">}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">NS</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;ns&#39;</span>
            <span class="n">name_server</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FixHostname</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="p">),</span> <span class="n">origin</span><span class="p">)</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;name_server&#39;</span><span class="p">:</span> <span class="n">name_server</span><span class="p">}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">SRV</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;srv&#39;</span>
            <span class="n">assignment_host</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FixHostname</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="o">.</span><span class="n">target</span><span class="p">),</span> <span class="n">origin</span><span class="p">)</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;priority&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">priority</span><span class="p">,</span>
                                <span class="s">u&#39;weight&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">weight</span><span class="p">,</span>
                                <span class="s">u&#39;port&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">port</span><span class="p">,</span>
                                <span class="s">u&#39;assignment_host&#39;</span><span class="p">:</span> <span class="n">assignment_host</span><span class="p">}</span>

          <span class="k">elif</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">SOA</span> <span class="p">):</span>
            <span class="n">record_type</span> <span class="o">=</span> <span class="s">u&#39;soa&#39;</span>
            <span class="n">name_server</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FixHostname</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="o">.</span><span class="n">mname</span><span class="p">),</span> <span class="n">origin</span><span class="p">)</span>
            <span class="n">admin_email</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FixHostname</span><span class="p">(</span><span class="nb">unicode</span><span class="p">(</span><span class="n">record_object</span><span class="o">.</span><span class="n">rname</span><span class="p">),</span> <span class="n">origin</span><span class="p">)</span>
            <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">u&#39;name_server&#39;</span><span class="p">:</span> <span class="n">name_server</span><span class="p">,</span>
                                <span class="s">u&#39;admin_email&#39;</span><span class="p">:</span> <span class="n">admin_email</span><span class="p">,</span>
                                <span class="s">u&#39;serial_number&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">serial</span><span class="p">,</span>
                                <span class="s">u&#39;retry_seconds&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">retry</span><span class="p">,</span>
                                <span class="s">u&#39;refresh_seconds&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">refresh</span><span class="p">,</span>
                                <span class="s">u&#39;expiry_seconds&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">expire</span><span class="p">,</span>
                                <span class="s">u&#39;minimum_seconds&#39;</span><span class="p">:</span> <span class="n">record_object</span><span class="o">.</span><span class="n">minimum</span><span class="p">}</span>

          <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">UnexpectedDataError</span><span class="p">(</span>
                <span class="s">&#39;Unkown record type: </span><span class="si">%s</span><span class="s">.</span><span class="se">\n</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
                    <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">to_text</span><span class="p">(</span><span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span><span class="p">),</span> <span class="n">record_object</span><span class="p">))</span>

          <span class="k">if</span><span class="p">(</span> <span class="n">record_object</span><span class="o">.</span><span class="n">rdtype</span> <span class="o">==</span> <span class="n">dns</span><span class="o">.</span><span class="n">rdatatype</span><span class="o">.</span><span class="n">SOA</span> <span class="ow">and</span> <span class="n">view</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span><span class="p">):</span>
            <span class="n">all_views</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListZones</span><span class="p">(</span><span class="n">zone_name</span><span class="o">=</span><span class="n">zone_name</span><span class="p">)[</span><span class="n">zone_name</span><span class="p">]</span>

            <span class="k">for</span> <span class="n">single_view</span> <span class="ow">in</span> <span class="n">all_views</span><span class="p">:</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">single_view</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
                <span class="n">make_record_args_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                  <span class="p">{</span><span class="s">u&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span>
                   <span class="s">u&#39;record_target&#39;</span><span class="p">:</span> <span class="n">record_target</span><span class="p">,</span>
                   <span class="s">u&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                   <span class="s">u&#39;record_arguments&#39;</span><span class="p">:</span> <span class="n">record_args_dict</span><span class="p">,</span>
                   <span class="s">u&#39;record_view_dependency&#39;</span><span class="p">:</span> <span class="n">single_view</span><span class="p">,</span>
                   <span class="s">u&#39;ttl&#39;</span><span class="p">:</span> <span class="n">ttl</span><span class="p">})</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">make_record_args_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">{</span><span class="s">u&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record_type</span><span class="p">,</span>
                 <span class="s">u&#39;record_target&#39;</span><span class="p">:</span> <span class="n">record_target</span><span class="p">,</span>
                 <span class="s">u&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span>
                 <span class="s">u&#39;record_arguments&#39;</span><span class="p">:</span> <span class="n">record_args_dict</span><span class="p">,</span>
                 <span class="s">u&#39;record_view_dependency&#39;</span><span class="p">:</span> <span class="n">view</span><span class="p">,</span>
                 <span class="s">u&#39;ttl&#39;</span><span class="p">:</span> <span class="n">ttl</span><span class="p">})</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">ProcessRecordsBatch</span><span class="p">(</span><span class="n">add_records</span><span class="o">=</span><span class="n">make_record_args_list</span><span class="p">,</span> <span class="n">zone_import</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">make_record_args_list</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.GetCIDRBlocksByView"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.GetCIDRBlocksByView">[docs]</a>  <span class="k">def</span> <span class="nf">GetCIDRBlocksByView</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">view</span><span class="p">,</span> <span class="n">username</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists CIDR blocks available to a username in a given view</span>

<span class="sd">    Inputs:</span>
<span class="sd">        view: string of view name</span>
<span class="sd">        username: string of user name</span>

<span class="sd">    Outputs:</span>
<span class="sd">        list: list of cidr block strings</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;GetCIDRBlocksByView&#39;</span><span class="p">)</span>
    <span class="n">cidrs</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([])</span>
    <span class="n">users_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;users&#39;</span><span class="p">)</span>
    <span class="n">users_dict</span><span class="p">[</span><span class="s">&#39;user_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">username</span>
    <span class="n">views_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;views&#39;</span><span class="p">)</span>
    <span class="n">views_dict</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view</span>

    <span class="n">user_group_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;user_group_assignments&#39;</span><span class="p">)</span>
    <span class="n">groups_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
    <span class="n">reverse_range_permissions_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">)</span>
    <span class="n">zones_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">)</span>
    <span class="n">reverse_range_zone_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;reverse_range_zone_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">joined_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
          <span class="s">&#39;views&#39;</span><span class="p">,</span> <span class="n">views_dict</span><span class="p">,</span>
          <span class="s">&#39;users&#39;</span><span class="p">,</span> <span class="n">users_dict</span><span class="p">,</span> <span class="s">&#39;user_group_assignments&#39;</span><span class="p">,</span>
          <span class="n">user_group_assignments_dict</span><span class="p">,</span>
          <span class="s">&#39;groups&#39;</span><span class="p">,</span> <span class="n">groups_dict</span><span class="p">,</span> <span class="s">&#39;reverse_range_permissions&#39;</span><span class="p">,</span>
          <span class="n">reverse_range_permissions_dict</span><span class="p">,</span> <span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zones_dict</span><span class="p">,</span>
          <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">,</span>
          <span class="s">&#39;reverse_range_zone_assignments&#39;</span><span class="p">,</span> <span class="n">reverse_range_zone_assignments_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">cidr_dict</span> <span class="ow">in</span> <span class="n">joined_list</span><span class="p">:</span>
      <span class="n">cidrs</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">cidr_dict</span><span class="p">[</span><span class="s">&#39;reverse_range_zone_assignments_cidr_block&#39;</span><span class="p">])</span>

    <span class="k">return</span> <span class="n">cidrs</span>
</div>
<div class="viewcode-block" id="CoreHelpers.GetAssociatedCNAMEs"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.GetAssociatedCNAMEs">[docs]</a>  <span class="k">def</span> <span class="nf">GetAssociatedCNAMEs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">hostname</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span>
                          <span class="n">recursive</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists cname&#39;s by assignment hostname.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      hostname: string of hostname</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      zone_name: string of zone name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      list: list of found cname dictionaries</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;GetAssociatedCNAMEs&#39;</span><span class="p">)</span>
    <span class="n">record_arguments_record_assignments_dict</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">))</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span>
         <span class="n">zone_name</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span><span class="p">[</span><span class="s">&#39;zone_view_assignments_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
         <span class="nb">unicode</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span><span class="p">))</span>

    <span class="n">record_arguments_record_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;record_arguments_records_assignments_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
    <span class="n">record_arguments_record_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;argument_value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">hostname</span>
    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">found_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
          <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">,</span>
          <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
          <span class="n">record_arguments_record_assignments_dict</span><span class="p">,</span>
          <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="n">cnames</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">found_records</span><span class="p">:</span>
      <span class="n">new_record</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span>
          <span class="s">&#39;record_arguments_records_assignments_type&#39;</span><span class="p">]</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span>
          <span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">rsplit</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;argument_value&#39;</span><span class="p">]</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;last_user&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span>
      <span class="n">cnames</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_record</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">recursive</span> <span class="p">):</span>
      <span class="k">return</span> <span class="n">cnames</span>
    <span class="n">new_cnames</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">cnames</span><span class="p">:</span>
      <span class="n">new_cnames</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">GetAssociatedCNAMEs</span><span class="p">(</span>
          <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;target&#39;</span><span class="p">],</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]),</span>
          <span class="n">record</span><span class="p">[</span><span class="s">&#39;view_name&#39;</span><span class="p">],</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;zone_name&#39;</span><span class="p">],</span> <span class="n">recursive</span><span class="o">=</span><span class="n">recursive</span><span class="p">))</span>
    <span class="n">cnames</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">new_cnames</span><span class="p">)</span>
    <span class="k">del</span> <span class="n">new_cnames</span>
    <span class="k">del</span> <span class="n">found_records</span>

    <span class="k">return</span> <span class="n">cnames</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListLatestNamedConfig"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListLatestNamedConfig">[docs]</a>  <span class="k">def</span> <span class="nf">ListLatestNamedConfig</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_set</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists the latest named config string given dns server set</span>

<span class="sd">    This function is duplicated in</span>
<span class="sd">    roster-config-manager/roster_config_manager/tree_exporter.py</span>

<span class="sd">    Inputs:</span>
<span class="sd">      dns_server_set: string of dns server set name</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dict: dictionary of latest named config</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">named_configs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListNamedConfGlobalOptions</span><span class="p">(</span>
        <span class="n">dns_server_set</span><span class="o">=</span><span class="n">dns_server_set</span><span class="p">)</span>
    <span class="n">current_timestamp</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
    <span class="n">smallest_time_differential</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">timedelta</span><span class="p">(</span><span class="n">weeks</span><span class="o">=</span><span class="mi">100000</span><span class="p">)</span>
    <span class="n">newest_config</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="k">for</span> <span class="n">named_config</span> <span class="ow">in</span> <span class="n">named_configs</span><span class="p">:</span>
      <span class="n">time_differential</span> <span class="o">=</span> <span class="n">current_timestamp</span> <span class="o">-</span> <span class="n">named_config</span><span class="p">[</span><span class="s">&#39;timestamp&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">time_differential</span> <span class="o">&lt;</span> <span class="n">smallest_time_differential</span> <span class="p">):</span>
        <span class="n">smallest_time_differential</span> <span class="o">=</span> <span class="n">time_differential</span>
        <span class="n">newest_config</span> <span class="o">=</span> <span class="n">named_config</span>

    <span class="k">return</span> <span class="n">newest_config</span>
</div>
<div class="viewcode-block" id="CoreHelpers.RevertNamedConfig"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.RevertNamedConfig">[docs]</a>  <span class="k">def</span> <span class="nf">RevertNamedConfig</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dns_server_set</span><span class="p">,</span> <span class="n">option_id</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Revert a Named Config file</span>

<span class="sd">    Inputs:</span>
<span class="sd">      option_id: the id of config to replicate</span>
<span class="sd">      dns_server_set: string of dns server set name</span>
<span class="sd">    </span>
<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: DNS server set does not contain id.</span>
<span class="sd">      UnexpectedDataError: Multiple configurations found.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">named_config</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListNamedConfGlobalOptions</span><span class="p">(</span>
        <span class="n">dns_server_set</span><span class="o">=</span><span class="n">dns_server_set</span><span class="p">,</span> <span class="n">option_id</span><span class="o">=</span><span class="n">option_id</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">named_config</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
        <span class="s">&#39;DNS server set &quot;</span><span class="si">%s</span><span class="s">&quot; does not contain id &quot;</span><span class="si">%s</span><span class="s">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">dns_server_set</span><span class="p">,</span> <span class="n">option_id</span><span class="p">))</span>
    <span class="k">elif</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">named_config</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="p">):</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">MakeNamedConfGlobalOption</span><span class="p">(</span>
          <span class="n">dns_server_set</span><span class="p">,</span> <span class="n">named_config</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">&#39;options&#39;</span><span class="p">])</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">UnexpectedDataError</span><span class="p">(</span><span class="s">&#39;Multiple configurations found.&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.MakeAAAARecord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.MakeAAAARecord">[docs]</a>  <span class="k">def</span> <span class="nf">MakeAAAARecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                     <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes an AAAA record.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      target: string of target</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      record_args_dict: dictionary of record arguments</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      ttl: time to live</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">record_args_dict</span><span class="p">[</span>
        <span class="s">&#39;assignment_ip&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">())</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">MakeRecord</span><span class="p">(</span><span class="s">u&#39;aaaa&#39;</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                                  <span class="n">view_name</span><span class="p">,</span> <span class="n">ttl</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.MakeSubdomainDelegation"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.MakeSubdomainDelegation">[docs]</a>  <span class="k">def</span> <span class="nf">MakeSubdomainDelegation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">subdomain_name</span><span class="p">,</span> <span class="n">nameserver</span><span class="p">,</span> 
                              <span class="n">view_name</span><span class="o">=</span><span class="s">u&#39;any&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;&quot;Makes a Delegated Subdomain</span>
<span class="sd">    Assumes delegation zone is created</span>

<span class="sd">    Inputs:</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">      subdomain_name: string of subdomain name </span>
<span class="sd">      nameserver: string of fully qualified nameserver</span>
<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: Zone does not exist.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">MakeRecord</span><span class="p">(</span><span class="s">u&#39;ns&#39;</span><span class="p">,</span> <span class="n">subdomain_name</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span>
                                  <span class="p">{</span><span class="s">u&#39;name_server&#39;</span><span class="p">:</span><span class="n">nameserver</span><span class="p">},</span> <span class="n">view_name</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.GetPTRTarget"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.GetPTRTarget">[docs]</a>  <span class="k">def</span> <span class="nf">GetPTRTarget</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">long_target</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="s">u&#39;any&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Gets the short PTR target given the long PTR target</span>
<span class="sd">    Inputs:</span>
<span class="sd">      long_target: String of long PTR target</span>
<span class="sd">      view_name: String of view name</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: No suitable reverse range zone assignments found.</span>
<span class="sd">    Outputs:</span>
<span class="sd">      string: String of short PTR target</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">long_target</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;in-addr.arpa.&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span>
        <span class="n">long_target</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;ip6.arpa.&#39;</span><span class="p">)</span> <span class="p">):</span>
      <span class="n">long_target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ReverseIP</span><span class="p">(</span><span class="n">long_target</span><span class="p">)</span>
    <span class="n">zone_assignment</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">reverse_range_zone_assignments</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListReverseRangeZoneAssignments</span><span class="p">())</span>
    <span class="n">ip_address</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">UnReverseIP</span><span class="p">(</span><span class="n">long_target</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">zone_assignment</span> <span class="ow">in</span> <span class="n">reverse_range_zone_assignments</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">zone_assignment</span> <span class="ow">in</span> <span class="n">reverse_range_zone_assignments</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">ip_address</span> <span class="ow">in</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span>
            <span class="n">reverse_range_zone_assignments</span><span class="p">[</span><span class="n">zone_assignment</span><span class="p">])</span> <span class="p">):</span>
          <span class="k">break</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
          <span class="s">&#39;No suitable reverse range zone assignments found.&#39;</span><span class="p">)</span>
    <span class="n">zone_detail</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListZones</span><span class="p">(</span><span class="n">view_name</span><span class="o">=</span><span class="n">view_name</span><span class="p">)</span>
    <span class="n">zone_origin</span> <span class="o">=</span> <span class="n">zone_detail</span><span class="p">[</span><span class="n">zone_assignment</span><span class="p">][</span><span class="n">view_name</span><span class="p">][</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span>
    <span class="c"># Count number of characters in zone origin, add one to count the extra</span>
    <span class="c"># period and remove that number of characters from the target.</span>
    <span class="n">zone_origin_length</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">zone_origin</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
    <span class="n">short_target</span> <span class="o">=</span> <span class="n">long_target</span><span class="p">[:</span><span class="o">-</span><span class="n">zone_origin_length</span><span class="p">]</span>

    <span class="k">return</span> <span class="p">(</span><span class="n">short_target</span><span class="p">,</span> <span class="n">zone_assignment</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.MakePTRRecord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.MakePTRRecord">[docs]</a>  <span class="k">def</span> <span class="nf">MakePTRRecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                    <span class="n">view_name</span><span class="o">=</span><span class="s">u&#39;any&#39;</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Makes a ptr record.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      target: string of target</span>
<span class="sd">      record_args_dict: dictionary of record arguments</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      ttl: string of ttl</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">target</span><span class="p">,</span> <span class="n">zone_assignment</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">GetPTRTarget</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">view_name</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;@.&#39;</span><span class="p">)</span> <span class="p">):</span>
      <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_args_dict</span><span class="p">[</span>
          <span class="s">&#39;assignment_host&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s">&#39;@.&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">MakeRecord</span><span class="p">(</span><span class="s">u&#39;ptr&#39;</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">zone_assignment</span><span class="p">,</span>
                                  <span class="n">record_args_dict</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">ttl</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.RemovePTRRecord"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.RemovePTRRecord">[docs]</a>  <span class="k">def</span> <span class="nf">RemovePTRRecord</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_type</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">record_args_dict</span><span class="p">,</span>
                      <span class="n">view_name</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes a ptr record.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      target: string of target</span>
<span class="sd">      record_args_dict: dictionary of record arguments</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      ttl: string of ttl</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;@.&#39;</span><span class="p">)</span> <span class="p">):</span>
      <span class="n">record_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_args_dict</span><span class="p">[</span>
          <span class="s">&#39;assignment_host&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s">&#39;@.&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">RemoveRecord</span><span class="p">(</span><span class="n">record_type</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span>
                                    <span class="n">record_args_dict</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">ttl</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.MakeIPv4ClasslessReverseDelegation"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.MakeIPv4ClasslessReverseDelegation">[docs]</a>  <span class="k">def</span> <span class="nf">MakeIPv4ClasslessReverseDelegation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name_server</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">,</span>
                                     <span class="n">view_name</span><span class="o">=</span><span class="s">u&#39;any&#39;</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Creates classless forwarding for reverse DNS lookups</span>

<span class="sd">    Inputs:</span>
<span class="sd">      name_server: nameserver to add for reverse delegation</span>
<span class="sd">      cidr_block: string of CIDR block</span>
<span class="sd">      view_name: string of view for the reverse zone, defaults to &#39;any&#39;</span>
<span class="sd">      ttl: time-to-live for the newly added records, defaults to zone ttl</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: nameserver required</span>
<span class="sd">      InvalidInputError: cidr block range required</span>
<span class="sd">      InvalidInputError: Not a valid zone name or CIDR block</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">view_dep</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>
    <span class="n">cidr_octets</span> <span class="o">=</span> <span class="n">cidr_block</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span>
    <span class="n">num_octets</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">num_octets</span> <span class="o">!=</span> <span class="mi">4</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR octet number&#39;</span><span class="p">)</span>
    <span class="n">cidr_block_target</span> <span class="o">=</span> <span class="n">cidr_octets</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">broadcast_last_octet</span> <span class="o">=</span> <span class="n">cidr_block_target</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">netmask</span> <span class="o">=</span> <span class="n">cidr_block_target</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">if</span><span class="p">(</span> <span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">))</span> <span class="ow">and</span> <span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">netmask</span><span class="p">))):</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">int</span><span class="p">(</span><span class="n">netmask</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">25</span> <span class="ow">or</span> <span class="nb">int</span><span class="p">(</span><span class="n">netmask</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">31</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR netmask: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">netmask</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">int</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="nb">int</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">255</span><span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR last octet&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR last octet/netmask&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">int</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="nb">int</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">255</span><span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR octet </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span>
                                         <span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR octet </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span>
                                         <span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

    <span class="n">cidr_for_ipy</span> <span class="o">=</span> <span class="n">cidr_octets</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">num_octets</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
      <span class="n">cidr_for_ipy</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cidr_for_ipy</span><span class="p">,</span> <span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
    <span class="n">cidr_for_ipy</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">/</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cidr_for_ipy</span><span class="p">,</span> <span class="s">&#39;0&#39;</span><span class="p">,</span> <span class="n">netmask</span><span class="p">)</span>
    <span class="n">expanded_cidr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">CIDRExpand</span><span class="p">(</span><span class="n">cidr_for_ipy</span><span class="p">,</span>
                                    <span class="n">begin</span><span class="o">=</span><span class="nb">long</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">))</span>
    <span class="n">expanded_cidr</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">expanded_cidr</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

    <span class="n">zone_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ListZoneByIPAddress</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">zone_name</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
          <span class="s">&#39;ERROR: zone that includes cidr block </span><span class="si">%s</span><span class="s"> not found&#39;</span> <span class="o">%</span> <span class="n">cidr_block</span><span class="p">)</span>

    <span class="n">records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListRecords</span><span class="p">(</span><span class="n">zone_name</span><span class="o">=</span><span class="n">zone_name</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records</span><span class="p">:</span>
      <span class="k">for</span> <span class="n">ip</span> <span class="ow">in</span> <span class="n">expanded_cidr</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">ReverseIP</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;target&#39;</span><span class="p">]</span> <span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;ERROR: existing record(s) with &#39;</span>
                                         <span class="s">&#39;target: </span><span class="si">%s</span><span class="s"> overlaps given cidr: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span>
                                         <span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;target&#39;</span><span class="p">],</span> <span class="n">cidr_block</span><span class="p">))</span>

    <span class="n">records_batch</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">cidr_last_target</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">)</span> <span class="o">+</span> <span class="nb">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">32</span> <span class="o">-</span> <span class="nb">int</span><span class="p">(</span><span class="n">netmask</span><span class="p">))</span>
    <span class="n">ns_target</span> <span class="o">=</span> <span class="n">cidr_block_target</span>
    <span class="n">ns_args_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">GetEmptyRecordArgsDict</span><span class="p">(</span><span class="s">u&#39;ns&#39;</span><span class="p">)</span>
    <span class="n">ns_args_dict</span><span class="p">[</span><span class="s">&#39;name_server&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">name_server</span>
    <span class="n">ns_record</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="s">u&#39;ns&#39;</span><span class="p">,</span> <span class="s">&#39;record_target&#39;</span><span class="p">:</span> <span class="n">ns_target</span><span class="p">,</span>
                 <span class="s">&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span> <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
                 <span class="s">&#39;record_view_dependency&#39;</span><span class="p">:</span> <span class="n">view_dep</span><span class="p">,</span>
                 <span class="s">&#39;record_arguments&#39;</span><span class="p">:</span> <span class="n">ns_args_dict</span><span class="p">}</span>
    <span class="n">records_batch</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ns_record</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">ip</span> <span class="ow">in</span> <span class="n">expanded_cidr</span><span class="p">:</span>
      <span class="n">reverse_ip</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ReverseIP</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span>
      <span class="n">split_reverse_ip</span> <span class="o">=</span> <span class="n">reverse_ip</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span>
      <span class="n">target</span> <span class="o">=</span> <span class="n">split_reverse_ip</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">reverse_ip_for_record</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">cidr_block_target</span><span class="p">)</span>
      <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">split_reverse_ip</span><span class="p">)):</span>
        <span class="n">reverse_ip_for_record</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">reverse_ip_for_record</span><span class="p">,</span>
                                           <span class="n">split_reverse_ip</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">target</span> <span class="o">==</span> <span class="n">broadcast_last_octet</span> <span class="ow">or</span> <span class="n">target</span> <span class="o">==</span> <span class="nb">unicode</span><span class="p">(</span>
             <span class="n">cidr_last_target</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="p">):</span>
        <span class="k">continue</span>
      <span class="n">cname_args_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">GetEmptyRecordArgsDict</span><span class="p">(</span><span class="s">u&#39;cname&#39;</span><span class="p">)</span>
      <span class="n">cname_args_dict</span><span class="p">[</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">reverse_ip_for_record</span><span class="p">)</span>
      <span class="n">cname_record</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="s">u&#39;cname&#39;</span><span class="p">,</span> <span class="s">&#39;record_target&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">target</span><span class="p">),</span>
                      <span class="s">&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="n">zone_name</span><span class="p">,</span> <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
                      <span class="s">&#39;record_view_dependency&#39;</span><span class="p">:</span> <span class="n">view_dep</span><span class="p">,</span>
                      <span class="s">&#39;record_arguments&#39;</span><span class="p">:</span> <span class="n">cname_args_dict</span><span class="p">}</span>
      <span class="n">records_batch</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cname_record</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">ProcessRecordsBatch</span><span class="p">(</span><span class="n">add_records</span><span class="o">=</span><span class="n">records_batch</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.MakeIPv4ClasslessReverseDelegatedTargetZone"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.MakeIPv4ClasslessReverseDelegatedTargetZone">[docs]</a>  <span class="k">def</span> <span class="nf">MakeIPv4ClasslessReverseDelegatedTargetZone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Creates a delegated reverse zone</span>

<span class="sd">    Inputs:</span>
<span class="sd">      cidr_block: string of IPv4 cidr block</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: Not a valid cidr block</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">cidr_octets</span> <span class="o">=</span> <span class="n">cidr_block</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span>
    <span class="n">cidr_block_target</span> <span class="o">=</span> <span class="n">cidr_octets</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">broadcast_last_octet</span> <span class="o">=</span> <span class="n">cidr_block_target</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">netmask</span> <span class="o">=</span> <span class="n">cidr_block_target</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>

    <span class="k">if</span><span class="p">(</span> <span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">))</span> <span class="ow">and</span> <span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">netmask</span><span class="p">))):</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">int</span><span class="p">(</span><span class="n">netmask</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">25</span> <span class="ow">or</span> <span class="nb">int</span><span class="p">(</span><span class="n">netmask</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">31</span> <span class="ow">or</span>
          <span class="nb">int</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="nb">int</span><span class="p">(</span><span class="n">broadcast_last_octet</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">255</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR block&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR block&#39;</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span> <span class="p">):</span>
        <span class="k">if</span><span class="p">(</span> <span class="nb">int</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="nb">int</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">255</span><span class="p">):</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR block&#39;</span><span class="p">)</span>
      <span class="k">else</span><span class="p">:</span>
          <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Invalid CIDR block&#39;</span><span class="p">)</span>

    <span class="n">zone_name</span> <span class="o">=</span> <span class="s">u&#39;in-addr.arpa&#39;</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cidr_octets</span><span class="p">)):</span>
      <span class="n">zone_name</span> <span class="o">=</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cidr_octets</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">zone_name</span><span class="p">)</span>
    <span class="n">zone_type</span> <span class="o">=</span> <span class="s">u&#39;master&#39;</span>
    <span class="n">zone_origin</span> <span class="o">=</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="n">zone_name</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">MakeZone</span><span class="p">(</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">zone_type</span><span class="p">,</span> <span class="n">zone_origin</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListAccessLevels"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListAccessLevels">[docs]</a>  <span class="k">def</span> <span class="nf">ListAccessLevels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists access levels from constants for both integer and string keys</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dict: dictionary of access levels with both string and integer-string keys</span>

<span class="sd">    Example:</span>
<span class="sd">      {&#39;32&#39;: 32, &#39;64&#39;: 64, &#39;128&#39;: 128, &#39;user&#39;: 32, &#39;unlocked_user&#39;: 64,</span>
<span class="sd">       &#39;dns_admin&#39;: 128}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">access_levels_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">constants</span><span class="o">.</span><span class="n">ACCESS_LEVELS</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
      <span class="n">access_levels_dict</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">)]</span> <span class="o">=</span> <span class="n">value</span>
      <span class="n">access_levels_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
    <span class="k">return</span> <span class="n">access_levels_dict</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListAvailableIpsInCIDR"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListAvailableIpsInCIDR">[docs]</a>  <span class="k">def</span> <span class="nf">ListAvailableIpsInCIDR</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">,</span> <span class="n">num_ips</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                             <span class="n">zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Finds first available ips. Only lists as many IPs as are available.</span>
<span class="sd">    Returns empty list if no IPs are available in given cidr block and a</span>
<span class="sd">    truncated list if only a portion of IPs are available.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      cidr_block: string of ipv4 or ipv6 cidr block</span>

<span class="sd">    Raises:</span>
<span class="sd">      InvalidInputError: IP is in a reserved IP space.</span>
<span class="sd">      InvalidInputError: Not a valid cidr block</span>
<span class="sd">    Outputs:</span>
<span class="sd">      list: list of strings of ip addresses</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">cidr_block_ipy</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
          <span class="s">&#39;</span><span class="si">%s</span><span class="s"> is not a valid cidr block&#39;</span> <span class="o">%</span> <span class="n">cidr_block</span><span class="p">)</span>
    <span class="n">reserved_ips</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">cidr_block_ipy</span><span class="o">.</span><span class="n">version</span><span class="p">()</span> <span class="o">==</span> <span class="mi">6</span> <span class="p">):</span>
      <span class="n">reserved</span> <span class="o">=</span> <span class="n">constants</span><span class="o">.</span><span class="n">RESERVED_IPV6</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">cidr_block_ipy</span><span class="o">.</span><span class="n">version</span><span class="p">()</span> <span class="o">==</span> <span class="mi">4</span> <span class="p">):</span>
      <span class="n">reserved</span> <span class="o">=</span> <span class="n">constants</span><span class="o">.</span><span class="n">RESERVED_IPV4</span>
    <span class="k">for</span> <span class="n">cidr</span> <span class="ow">in</span> <span class="n">reserved</span><span class="p">:</span>
      <span class="n">reserved_ips</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">cidr</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">reserved_ip</span> <span class="ow">in</span> <span class="n">reserved_ips</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">)</span> <span class="ow">in</span> <span class="n">reserved_ip</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
            <span class="s">&#39;</span><span class="si">%s</span><span class="s"> is in a reserved IP space&#39;</span> <span class="o">%</span> <span class="n">cidr_block</span><span class="p">)</span>
    <span class="n">records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ListRecordsByCIDRBlock</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="n">view_name</span><span class="p">,</span>
                                          <span class="n">zone_name</span><span class="o">=</span><span class="n">zone_name</span><span class="p">)</span>
    <span class="n">taken_ips</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">avail_ips</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">view</span> <span class="ow">in</span> <span class="n">records</span><span class="p">:</span>
      <span class="k">for</span> <span class="n">ip</span> <span class="ow">in</span> <span class="n">records</span><span class="p">[</span><span class="n">view</span><span class="p">]:</span>
        <span class="n">taken_ips</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span>
    <span class="n">count</span> <span class="o">=</span> <span class="il">0L</span>
    <span class="k">while</span><span class="p">(</span> <span class="n">count</span> <span class="o">&lt;</span> <span class="n">cidr_block_ipy</span><span class="o">.</span><span class="n">len</span><span class="p">()</span> <span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">avail_ips</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="n">num_ips</span> <span class="p">):</span>
        <span class="k">break</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">cidr_block_ipy</span><span class="p">[</span><span class="n">count</span><span class="p">]</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">taken_ips</span> <span class="p">):</span>
        <span class="n">avail_ips</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cidr_block_ipy</span><span class="p">[</span><span class="n">count</span><span class="p">]</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">())</span>
      <span class="n">count</span> <span class="o">+=</span> <span class="il">1L</span>
    <span class="k">return</span> <span class="n">avail_ips</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListRecordsByCIDRBlock"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListRecordsByCIDRBlock">[docs]</a>  <span class="k">def</span> <span class="nf">ListRecordsByCIDRBlock</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr_block</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists records in a given cidr block.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      cidr_block: string of ipv4 or ipv6 cidr block</span>
<span class="sd">      view_name: string of the view</span>
<span class="sd">      zone_name: string of the zone</span>
<span class="sd">    </span>
<span class="sd">    Raise:</span>
<span class="sd">      InvalidInputError: The CIDR block specified does not contain a valid IP</span>
<span class="sd">      IPIndexError: Record type not indexable by IP</span>
<span class="sd">      IPIndexError: Record type unknown. Missing ipv4 or ipv6 dec index</span>

<span class="sd">    Outputs:</span>
<span class="sd">      dict: A dictionary Keyed by view, keyed by IP, listed by record.</span>
<span class="sd">            example:</span>
<span class="sd">                {u&#39;test_view&#39;:</span>
<span class="sd">                    {u&#39;192.168.1.8&#39;:</span>
<span class="sd">                        [{u&#39;forward&#39;: True,</span>
<span class="sd">                          u&#39;host&#39;: u&#39;host6.university.edu&#39;,</span>
<span class="sd">                          u&#39;zone&#39;: u&#39;forward_zone&#39;,</span>
<span class="sd">                          u&#39;zone_origin&#39;: u&#39;university.edu.&#39;},</span>
<span class="sd">                         {u&#39;forward&#39;: False,</span>
<span class="sd">                          u&#39;host&#39;: u&#39;host6.university.edu&#39;,</span>
<span class="sd">                          u&#39;zone&#39;: u&#39;reverse_zone&#39;,</span>
<span class="sd">                          u&#39;zone_origin&#39;: u&#39;1.168.192.in-addr.arpa.&#39;}]}}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListRecordsByCIDRBlock&#39;</span><span class="p">)</span>
    <span class="n">record_list</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
      <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
          <span class="s">&#39;The CIDR block specified does not contain a valid IP: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
          <span class="n">cidr_block</span><span class="p">))</span>
    <span class="n">cidr_block</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">)</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">cidr_block</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span> <span class="p">):</span>
      <span class="n">cidr_ip</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">cidr_block</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
      <span class="n">cidr_size</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cidr_block</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">cidr_ip</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">cidr_block</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">cidr_ip</span><span class="o">.</span><span class="n">version</span><span class="p">()</span> <span class="o">==</span> <span class="mi">4</span> <span class="p">):</span>
        <span class="n">cidr_size</span> <span class="o">=</span> <span class="mi">32</span>
      <span class="k">elif</span><span class="p">(</span> <span class="n">cidr_ip</span><span class="o">.</span><span class="n">version</span><span class="p">()</span> <span class="o">==</span> <span class="mi">6</span> <span class="p">):</span>
        <span class="n">cidr_size</span> <span class="o">=</span> <span class="mi">128</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span>
            <span class="s">&#39;The CIDR block specified does not contain a valid IP: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">cidr_block</span><span class="p">))</span>
    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">)</span>
    <span class="n">record_arguments_records_assignments_dict</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">))</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span>
        <span class="n">view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>

    <span class="n">zone_dict</span><span class="p">[</span><span class="s">&#39;zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>

    <span class="k">if</span><span class="p">(</span> <span class="n">cidr_ip</span><span class="o">.</span><span class="n">version</span><span class="p">()</span> <span class="o">==</span> <span class="mi">4</span> <span class="p">):</span>
      <span class="n">decimal_ip</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span> <span class="n">cidr_ip</span><span class="o">.</span><span class="n">strDec</span><span class="p">()</span> <span class="p">)</span>
      <span class="n">decimal_ip_lower</span> <span class="o">=</span> <span class="p">(</span>
          <span class="p">(</span><span class="n">decimal_ip</span> <span class="o">&gt;&gt;</span> <span class="p">(</span><span class="mi">32</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">)</span> <span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="p">(</span><span class="mi">32</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">))</span>
      <span class="n">decimal_ip_upper</span> <span class="o">=</span> <span class="p">(</span> <span class="nb">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">32</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">)</span> <span class="o">|</span> <span class="n">decimal_ip</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="n">ip_index_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;ipv4_index&#39;</span><span class="p">)</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">record_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;ipv4_index&#39;</span><span class="p">,</span> <span class="n">ip_index_dict</span><span class="p">,</span>
            <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">,</span>
            <span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zone_dict</span><span class="p">,</span>
            <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">,</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span> 
            <span class="n">record_arguments_records_assignments_dict</span><span class="p">,</span>
            <span class="n">column</span><span class="o">=</span><span class="s">&#39;ipv4_dec_address&#39;</span><span class="p">,</span>
            <span class="n">range_values</span><span class="o">=</span><span class="p">(</span><span class="n">decimal_ip_lower</span><span class="p">,</span> <span class="n">decimal_ip_upper</span><span class="p">))</span>
      <span class="k">finally</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">cidr_ip</span><span class="o">.</span><span class="n">version</span><span class="p">()</span> <span class="o">==</span> <span class="mi">6</span> <span class="p">):</span>
      <span class="n">ip_index_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;ipv6_index&#39;</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">cidr_size</span> <span class="o">&gt;=</span> <span class="mi">64</span> <span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
          <span class="n">ip_index_dict</span><span class="p">[</span><span class="s">u&#39;ipv6_dec_upper&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cidr_ip</span><span class="o">.</span><span class="n">strHex</span><span class="p">(</span><span class="mi">0</span><span class="p">)[:</span><span class="o">-</span><span class="mi">16</span><span class="p">],</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
          <span class="n">ip_index_dict</span><span class="p">[</span><span class="s">u&#39;ipv6_dec_upper&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">decimal_ip_lower</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s">&#39;0x</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">cidr_ip</span><span class="o">.</span><span class="n">strHex</span><span class="p">(</span><span class="mi">0</span><span class="p">)[</span><span class="mi">18</span><span class="p">:],</span> <span class="mi">0</span><span class="p">)</span>
        <span class="n">decimal_ip_lower_lower</span> <span class="o">=</span> <span class="p">(</span>
            <span class="p">(</span><span class="n">decimal_ip_lower</span> <span class="o">&gt;&gt;</span> <span class="p">(</span><span class="mi">128</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">))</span> <span class="o">&lt;&lt;</span>
            <span class="p">(</span><span class="mi">128</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">))</span>
        <span class="n">decimal_ip_lower_upper</span> <span class="o">=</span> <span class="p">(</span>
            <span class="p">(</span><span class="nb">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">128</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">)</span> <span class="o">|</span> <span class="n">decimal_ip_lower</span><span class="p">)</span>
        <span class="n">column</span> <span class="o">=</span> <span class="s">&#39;ipv6_dec_lower&#39;</span>
        <span class="n">range_values</span> <span class="o">=</span> <span class="p">(</span><span class="n">decimal_ip_lower_lower</span><span class="p">,</span> <span class="n">decimal_ip_lower_upper</span><span class="p">)</span>
      <span class="k">elif</span><span class="p">(</span> <span class="n">cidr_size</span> <span class="o">&lt;</span> <span class="mi">64</span> <span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
          <span class="n">decimal_ip_upper</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cidr_ip</span><span class="o">.</span><span class="n">strHex</span><span class="p">()[:</span><span class="o">-</span><span class="mi">16</span><span class="p">],</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
          <span class="n">decimal_ip_upper</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">decimal_ip_upper_lower</span> <span class="o">=</span> <span class="p">(</span>
            <span class="p">(</span><span class="n">decimal_ip_upper</span> <span class="o">&gt;&gt;</span> <span class="p">(</span><span class="mi">64</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="p">(</span><span class="mi">64</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">))</span>
        <span class="n">decimal_ip_upper_upper</span> <span class="o">=</span> <span class="p">(</span>
            <span class="p">(</span><span class="nb">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">64</span> <span class="o">-</span> <span class="n">cidr_size</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">)</span> <span class="o">|</span> <span class="n">decimal_ip_upper</span><span class="p">)</span>
        <span class="n">column</span> <span class="o">=</span> <span class="s">&#39;ipv6_dec_upper&#39;</span>
        <span class="n">range_values</span> <span class="o">=</span> <span class="p">(</span><span class="n">decimal_ip_upper_lower</span><span class="p">,</span> <span class="n">decimal_ip_upper_upper</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">record_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;ipv6_index&#39;</span><span class="p">,</span> <span class="n">ip_index_dict</span><span class="p">,</span>
            <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">,</span>
            <span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zone_dict</span><span class="p">,</span>
            <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">,</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
            <span class="n">record_arguments_records_assignments_dict</span><span class="p">,</span>
            <span class="n">column</span><span class="o">=</span><span class="n">column</span><span class="p">,</span>
            <span class="n">range_values</span><span class="o">=</span><span class="n">range_values</span><span class="p">)</span>
      <span class="k">finally</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>

    <span class="c">## Parse returned list</span>
    <span class="n">parsed_record_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">record_entry</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">record_list</span><span class="p">):</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span>
          <span class="n">constants</span><span class="o">.</span><span class="n">RECORD_TYPES_INDEXED_BY_IP</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">IPIndexError</span><span class="p">(</span><span class="s">&#39;Record type not indexable by &#39;</span>
                                  <span class="s">&#39;IP: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">record_entry</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="p">):</span>
        <span class="n">record_view</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">record_view</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_view</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed_record_dict</span> <span class="p">):</span>
        <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="k">if</span><span class="p">(</span> <span class="s">u&#39;ipv4_dec_address&#39;</span> <span class="ow">in</span> <span class="n">record_entry</span> <span class="p">):</span>
        <span class="n">record_ip</span> <span class="o">=</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;ipv4_dec_address&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">strNormal</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record_ip</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">]</span> <span class="p">):</span>
          <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">elif</span><span class="p">(</span> <span class="s">u&#39;ipv6_dec_upper&#39;</span> <span class="ow">in</span> <span class="n">record_entry</span> <span class="p">):</span>
        <span class="n">decimal_ip</span> <span class="o">=</span> <span class="p">(</span>
            <span class="p">(</span><span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;ipv6_dec_upper&#39;</span><span class="p">]</span> <span class="o">&lt;&lt;</span> <span class="mi">64</span><span class="p">)</span> <span class="o">+</span>
            <span class="p">(</span><span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;ipv6_dec_lower&#39;</span><span class="p">])</span> <span class="p">)</span>
        <span class="n">record_ip</span> <span class="o">=</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">decimal_ip</span><span class="p">)</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record_ip</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">]</span> <span class="p">):</span>
          <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">IPIndexError</span><span class="p">(</span>
            <span class="s">&#39;Record type unknown. Missing ipv4 or ipv6 dec index: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_entry</span><span class="p">))</span>
      <span class="n">record_item</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span>
          <span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span>
      <span class="c">#record_item[&#39;record_last_updated&#39;] = record_entry[&#39;record_last_updated&#39;]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span>
      <span class="k">if</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">):</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;a&#39;</span> <span class="ow">or</span>
          <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;aaaa&#39;</span> <span class="p">):</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;forward&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">],</span>
            <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_args_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;assignment_ip&#39;</span><span class="p">:</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;argument_value&#39;</span><span class="p">]}</span>
        <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">record_item</span> <span class="p">)</span>
      <span class="k">elif</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;forward&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;argument_value&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">assignment_ip</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnReverseIP</span><span class="p">(</span>
            <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
                <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">],</span><span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]))</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_args_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">:</span> <span class="n">assignment_ip</span><span class="p">}</span>
        <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">record_item</span> <span class="p">)</span>

    <span class="k">return</span> <span class="n">parsed_record_dict</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListRecordsByZone"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListRecordsByZone">[docs]</a>  <span class="k">def</span> <span class="nf">ListRecordsByZone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists records in a given zone.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      zone_name: name of the zone</span>
<span class="sd">      view_name: name of the view</span>
<span class="sd">    </span>
<span class="sd">    Output:</span>
<span class="sd">      dict: A dictionary Keyed by view, keyed by IP, listed by record.</span>
<span class="sd">            example:</span>
<span class="sd">                {u&#39;test_view&#39;:</span>
<span class="sd">                    {u&#39;192.168.1.8&#39;:</span>
<span class="sd">                        [{u&#39;forward&#39;: True,</span>
<span class="sd">                          u&#39;host&#39;: u&#39;host6.university.edu&#39;,</span>
<span class="sd">                          u&#39;zone&#39;: u&#39;forward_zone&#39;,</span>
<span class="sd">                          u&#39;zone_origin&#39;: u&#39;university.edu.&#39;},</span>
<span class="sd">                         {u&#39;forward&#39;: False,</span>
<span class="sd">                          u&#39;host&#39;: u&#39;host6.university.edu&#39;,</span>
<span class="sd">                          u&#39;zone&#39;: u&#39;reverse_zone&#39;,</span>
<span class="sd">                          u&#39;zone_origin&#39;: u&#39;1.168.192.in-addr.arpa.&#39;}]}}</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ListRecordsByZone&#39;</span><span class="p">)</span>
    <span class="n">record_list</span> <span class="o">=</span> <span class="p">{}</span>
    
    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">zone_view_assignments_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;zone_view_assignments&#39;</span><span class="p">)</span>
    <span class="n">zone_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;zones&#39;</span><span class="p">)</span>
    <span class="n">zone_dict</span><span class="p">[</span><span class="s">&#39;zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="n">record_arguments_records_assignments_dict</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">))</span>
    <span class="n">ipv4_index_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;ipv4_index&#39;</span><span class="p">)</span>
    <span class="n">ipv6_index_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;ipv6_index&#39;</span><span class="p">)</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span>
        <span class="n">view_name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">view_name</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
      <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">view_name</span>
    <span class="k">elif</span><span class="p">(</span> <span class="n">view_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="p">):</span>
      <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>

    <span class="n">args_ipv4</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;zone_view_assignments&#39;</span><span class="p">,</span> <span class="n">zone_view_assignments_dict</span><span class="p">,</span>
                 <span class="s">&#39;zones&#39;</span><span class="p">,</span> <span class="n">zone_dict</span><span class="p">,</span> <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">,</span>
                 <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
                 <span class="n">record_arguments_records_assignments_dict</span><span class="p">]</span>
    <span class="n">args_ipv6</span> <span class="o">=</span> <span class="n">args_ipv4</span> <span class="o">+</span> <span class="p">[</span><span class="s">&#39;ipv6_index&#39;</span><span class="p">,</span> <span class="n">ipv6_index_dict</span><span class="p">]</span>
    <span class="n">args_ipv4</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;ipv4_index&#39;</span><span class="p">)</span>
    <span class="n">args_ipv4</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ipv4_index_dict</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="n">record_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="o">*</span><span class="n">args_ipv4</span><span class="p">)</span>
      <span class="n">record_list</span> <span class="o">=</span> <span class="n">record_list</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="o">*</span><span class="n">args_ipv6</span><span class="p">)</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
    <span class="c">#Parsing Records</span>
    <span class="n">parsed_record_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">record_entry</span> <span class="ow">in</span> <span class="n">record_list</span><span class="p">:</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> 
          <span class="n">constants</span><span class="o">.</span><span class="n">RECORD_TYPES_INDEXED_BY_IP</span> <span class="p">):</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">IPIndexError</span><span class="p">(</span><span class="s">&#39;Record type not indexable by &#39;</span>
                                  <span class="s">&#39;IP: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">record_entry</span><span class="p">)</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="p">):</span>
        <span class="n">record_view</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">record_view</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_view</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed_record_dict</span> <span class="p">):</span>
          <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="k">if</span><span class="p">(</span> <span class="s">u&#39;ipv4_dec_address&#39;</span> <span class="ow">in</span> <span class="n">record_entry</span> <span class="p">):</span>
        <span class="n">record_ip</span> <span class="o">=</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;ipv4_dec_address&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">strNormal</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record_ip</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">]</span> <span class="p">):</span>
          <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">elif</span><span class="p">(</span> <span class="s">u&#39;ipv6_dec_upper&#39;</span> <span class="ow">in</span> <span class="n">record_entry</span> <span class="p">):</span>
        <span class="n">decimal_ip</span> <span class="o">=</span> <span class="p">(</span>
            <span class="p">(</span><span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;ipv6_dec_upper&#39;</span><span class="p">]</span> <span class="o">&lt;&lt;</span> <span class="mi">64</span><span class="p">)</span> <span class="o">+</span>
            <span class="p">(</span><span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;ipv6_dec_lower&#39;</span><span class="p">])</span> <span class="p">)</span>
        <span class="n">record_ip</span> <span class="o">=</span> <span class="s">u&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">decimal_ip</span><span class="p">)</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">if</span><span class="p">(</span> <span class="n">record_ip</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">]</span> <span class="p">):</span>
          <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">IPIndexError</span><span class="p">(</span>
            <span class="s">&#39;Record type unknown. Missing ipv4 or ipv6 dec index: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_entry</span><span class="p">))</span>
      <span class="n">record_item</span> <span class="o">=</span> <span class="p">{}</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span>
                                              <span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span>
      <span class="n">record_item</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span>
      <span class="k">if</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">):</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;view_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_view_dependency&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;a&#39;</span> <span class="ow">or</span>
          <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;aaaa&#39;</span> <span class="p">):</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;forward&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">],</span>
            <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_args_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;assignment_ip&#39;</span><span class="p">:</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;argument_value&#39;</span><span class="p">]}</span>
        <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record_item</span><span class="p">)</span>
      <span class="k">elif</span><span class="p">(</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;zone_origin&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;forward&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_entry</span><span class="p">[</span><span class="s">u&#39;argument_value&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">assignment_ip</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">UnReverseIP</span><span class="p">(</span>
            <span class="s">&#39;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
                <span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">],</span><span class="n">record_entry</span><span class="p">[</span><span class="s">&#39;zone_origin&#39;</span><span class="p">]))</span>
        <span class="n">record_item</span><span class="p">[</span><span class="s">u&#39;record_args_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;assignment_ip&#39;</span><span class="p">:</span> <span class="n">assignment_ip</span><span class="p">}</span>
        <span class="n">parsed_record_dict</span><span class="p">[</span><span class="n">record_view</span><span class="p">][</span><span class="n">record_ip</span><span class="p">]</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">record_item</span> <span class="p">)</span>
    <span class="k">return</span> <span class="n">parsed_record_dict</span>
</div>
<div class="viewcode-block" id="CoreHelpers.SortRecordsByHost"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.SortRecordsByHost">[docs]</a>  <span class="k">def</span> <span class="nf">SortRecordsByHost</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Generates an IP list sorted by record&#39;s host</span>
<span class="sd">    Inputs:</span>
<span class="sd">      record_dict: dictionary keyed by view, then keyed by IP</span>
<span class="sd">                   dictionary from ListRecordsByCIDRBlock</span>
<span class="sd">                   and from ListRecordsByZone</span>

<span class="sd">    Outputs:</span>
<span class="sd">      sorted_list: list of sorted records</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">sorted_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">target_sort</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">view</span> <span class="ow">in</span> <span class="n">records_dict</span><span class="p">:</span>
      <span class="k">for</span> <span class="n">ip</span> <span class="ow">in</span> <span class="n">records_dict</span><span class="p">[</span><span class="n">view</span><span class="p">]:</span>
        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records_dict</span><span class="p">[</span><span class="n">view</span><span class="p">][</span><span class="n">ip</span><span class="p">]:</span>
          <span class="n">target_sort</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">dict</span><span class="p">({</span><span class="s">&#39;ip_address&#39;</span><span class="p">:</span><span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">ip</span><span class="p">)</span><span class="o">.</span><span class="n">strFullsize</span><span class="p">()}</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="o">+</span> 
                                  <span class="n">record</span><span class="o">.</span><span class="n">items</span><span class="p">()))</span>
    <span class="n">sorted_list</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">target_sort</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="s">&#39;host&#39;</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">sorted_list</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListNamedConfGlobalOptionsClient"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListNamedConfGlobalOptionsClient">[docs]</a>  <span class="k">def</span> <span class="nf">ListNamedConfGlobalOptionsClient</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">option_id</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                                       <span class="n">dns_server_set</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">timestamp</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Converts XMLRPC datetime to datetime object and runs</span>
<span class="sd">    ListNamedConfGlobalOptions</span>

<span class="sd">    Inputs:</span>
<span class="sd">      option_id: integer of the option id</span>
<span class="sd">      dns_server_set: string of the dns server set name</span>
<span class="sd">      timestamp: XMLRPC datetime timestamp</span>

<span class="sd">    Outputs:</span>
<span class="sd">      list: list of dictionarires from ListNamedConfGlobalOptions</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="n">named_conf_global_options</span> <span class="o">=</span> <span class="bp">None</span>

    <span class="n">named_conf_global_options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListNamedConfGlobalOptions</span><span class="p">(</span>
        <span class="n">option_id</span><span class="p">,</span> <span class="n">dns_server_set</span><span class="p">,</span> <span class="n">timestamp</span><span class="p">)</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>

    <span class="k">return</span> <span class="n">named_conf_global_options</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListZoneByIPAddress"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListZoneByIPAddress">[docs]</a>  <span class="k">def</span> <span class="nf">ListZoneByIPAddress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ip_address</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Lists zone name given ip_address</span>

<span class="sd">    Inputs:</span>
<span class="sd">      ip_address: string of ip address</span>

<span class="sd">    Outputs:</span>
<span class="sd">      string: string of zone name, ex: &#39;test_zone&#39;</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">user_ip</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">ip_address</span><span class="p">)</span>
    <span class="n">reverse_range_zone_assignments</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">ListReverseRangeZoneAssignments</span><span class="p">())</span>
    <span class="k">for</span> <span class="n">reverse_range_zone_assignment</span> <span class="ow">in</span> <span class="n">reverse_range_zone_assignments</span><span class="p">:</span>
      <span class="n">db_cidr</span> <span class="o">=</span> <span class="n">IPy</span><span class="o">.</span><span class="n">IP</span><span class="p">(</span><span class="n">reverse_range_zone_assignments</span><span class="p">[</span>
          <span class="n">reverse_range_zone_assignment</span><span class="p">])</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">user_ip</span> <span class="ow">in</span> <span class="n">db_cidr</span> <span class="p">):</span>
        <span class="k">return</span> <span class="n">reverse_range_zone_assignment</span>
</div>
<div class="viewcode-block" id="CoreHelpers.RemoveCNamesByAssignmentHost"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.RemoveCNamesByAssignmentHost">[docs]</a>  <span class="k">def</span> <span class="nf">RemoveCNamesByAssignmentHost</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">hostname</span><span class="p">,</span> <span class="n">view_name</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Removes cname&#39;s by assignment hostname, will not remove cnames</span>
<span class="sd">    that the user does not have permissin to remove. The function will continue</span>
<span class="sd">    and pass over that cname.</span>

<span class="sd">    Inputs:</span>
<span class="sd">      hostname: string of hostname</span>
<span class="sd">      view_name: string of view name</span>
<span class="sd">      zone_name: string of zone name</span>
<span class="sd">    </span>
<span class="sd">    Raises:</span>
<span class="sd">      UnexpectedDataError: Incorrect number of records found</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: number of rows modified</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">record_arguments_record_assignments_dict</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">))</span>
    <span class="n">record_arguments_record_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;record_arguments_records_assignments_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
    <span class="n">record_arguments_record_assignments_dict</span><span class="p">[</span>
        <span class="s">&#39;argument_value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">hostname</span>
    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
        <span class="s">&#39;records&#39;</span><span class="p">)</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">view_name</span>
    <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">zone_name</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="n">found_record_arguments</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
            <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
            <span class="n">record_arguments_record_assignments_dict</span><span class="p">)</span>
        <span class="n">remove_record_dict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">record_argument</span> <span class="ow">in</span> <span class="n">found_record_arguments</span><span class="p">:</span>
          <span class="n">remove_record_dict</span><span class="p">[</span><span class="n">record_argument</span><span class="p">[</span>
              <span class="s">&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">{</span>
                  <span class="s">&#39;assignment_host&#39;</span><span class="p">:</span> <span class="n">record_argument</span><span class="p">[</span><span class="s">&#39;argument_value&#39;</span><span class="p">]}</span>
        <span class="k">for</span> <span class="n">record_id</span> <span class="ow">in</span> <span class="n">remove_record_dict</span><span class="p">:</span>
          <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_id</span>
          <span class="n">found_records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
              <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">found_records_dict</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span> <span class="p">):</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">UnexpectedDataError</span><span class="p">(</span>
                <span class="s">&#39;Incorrect number of records found!&#39;</span><span class="p">)</span>
          <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span>
                <span class="n">function_name</span><span class="p">,</span>
                 <span class="n">record_data</span><span class="o">=</span>
                     <span class="p">{</span><span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">found_records_dict</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">&#39;record_target&#39;</span><span class="p">],</span>
                      <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">],</span>
                      <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">],</span>
                      <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]},</span>

                <span class="n">current_transaction</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
          <span class="k">except</span> <span class="n">errors</span><span class="o">.</span><span class="n">AuthorizationError</span><span class="p">:</span>
            <span class="k">continue</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span>
              <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">found_records_dict</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
          <span class="n">remove_record_dict</span><span class="p">[</span><span class="n">record_id</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
              <span class="s">&#39;cname_host&#39;</span><span class="p">:</span> <span class="n">found_records_dict</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">&#39;record_target&#39;</span><span class="p">]})</span>
      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
      <span class="n">log_list</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">for</span> <span class="n">record_id</span> <span class="ow">in</span> <span class="n">remove_record_dict</span><span class="p">:</span>
        <span class="n">log_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;record_id:&#39;</span><span class="p">)</span>
        <span class="n">log_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">record_id</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">remove_record_dict</span><span class="p">[</span><span class="n">record_id</span><span class="p">]:</span>
          <span class="n">log_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">:&#39;</span> <span class="o">%</span> <span class="n">record</span><span class="p">)</span>
          <span class="n">log_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">remove_record_dict</span><span class="p">[</span><span class="n">record_id</span><span class="p">][</span><span class="n">record</span><span class="p">])</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ConstructRecordArgsDictFromRecordID"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ConstructRecordArgsDictFromRecordID">[docs]</a>  <span class="k">def</span> <span class="nf">ConstructRecordArgsDictFromRecordID</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record_id</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Constructs the records_arg_dict from the Roster database given only </span>
<span class="sd">    the record id.</span>

<span class="sd">    Inputs:</span>
<span class="sd">    record_id: int of record id</span>

<span class="sd">    Outputs:</span>
<span class="sd">    record_args_dict: dictionary of arguments and their values</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">record_args_db_row</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
      <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">)</span>
    <span class="n">record_args_db_row</span><span class="p">[</span>
        <span class="s">&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record_id</span>
    <span class="n">record_args_db_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
      <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span> <span class="n">record_args_db_row</span><span class="p">)</span>

    <span class="n">record_args_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">record_args_db_dict</span><span class="p">:</span>
      <span class="n">key_entry</span> <span class="o">=</span> <span class="n">key</span><span class="p">[</span><span class="s">&#39;argument_value&#39;</span><span class="p">]</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">key_entry</span><span class="o">.</span><span class="n">isdigit</span><span class="p">()</span> <span class="p">):</span>
        <span class="n">key_entry</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">key_entry</span><span class="p">)</span>
      <span class="n">record_args_dict</span><span class="p">[</span>
        <span class="n">key</span><span class="p">[</span><span class="s">&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="n">key_entry</span>

    <span class="k">return</span> <span class="n">record_args_dict</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ProcessRecordsBatch"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ProcessRecordsBatch">[docs]</a>  <span class="k">def</span> <span class="nf">ProcessRecordsBatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">delete_records</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">add_records</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                          <span class="n">zone_import</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Proccess batches of records</span>

<span class="sd">    Inputs:</span>
<span class="sd">      delete_records: list of dictionaries of records</span>
<span class="sd">                      ex: {&#39;record_ttl&#39;: 3600, &#39;record_type&#39;: u&#39;a&#39;,</span>
<span class="sd">                          &#39;records_id&#39;: 10, &#39;record_target&#39;: u&#39;host1&#39;,</span>
<span class="sd">                          &#39;record_zone_name&#39;: u&#39;forward_zone&#39;,</span>
<span class="sd">                          &#39;record_last_user&#39;: u&#39;sharrell&#39;,</span>
<span class="sd">                          &#39;record_view_dependency&#39;: u&#39;test_view_dep&#39;}</span>
<span class="sd">                          {&#39;record_type&#39;: &#39;ptr&#39;, &#39;record_target&#39;: &#39;target&#39;,</span>
<span class="sd">                          &#39;view_name&#39;: &#39;view&#39;, &#39;zone_name&#39;: &#39;zone&#39;}</span>
<span class="sd">      add_records: list of dictionaries of records</span>
<span class="sd">    </span>
<span class="sd">    Raises: </span>
<span class="sd">      RecordsBatchError: Record specification too broad</span>
<span class="sd">      RecordsBatchError: No record found</span>
<span class="sd">      RecordsBatchError: Record already exists</span>
<span class="sd">      RecordsBatchError: CNAME already exists</span>
<span class="sd">      RecordsBatchError: Duplicate record found</span>

<span class="sd">    Outputs:</span>
<span class="sd">      int: row count</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">delete_records</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
      <span class="n">delete_records</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">if</span> <span class="n">add_records</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
      <span class="n">add_records</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">function_name</span><span class="p">,</span> <span class="n">current_args</span> <span class="o">=</span> <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetFunctionNameAndArgs</span><span class="p">()</span>
    <span class="n">log_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;delete&#39;</span><span class="p">:</span> <span class="p">[],</span> <span class="s">&#39;add&#39;</span><span class="p">:</span> <span class="p">[]}</span>
    <span class="n">row_count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">changed_view_dep</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">add_records</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ValidateRecordArgsDict</span><span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">u&#39;record_type&#39;</span><span class="p">],</span> 
                                                <span class="n">record</span><span class="p">[</span><span class="s">u&#39;record_arguments&#39;</span><span class="p">])</span>

      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">StartTransaction</span><span class="p">()</span>
      <span class="k">try</span><span class="p">:</span>
        <span class="c"># REMOVE RECORDS</span>
        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">delete_records</span><span class="p">:</span>
          <span class="n">record_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">)</span>
          <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">]</span>
          <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span>
          <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]</span>
          <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="ow">or</span>
              <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;any&#39;</span> <span class="p">):</span>
            <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span>
                <span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
                <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">])</span>
          <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]</span>
          <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span>
          <span class="n">record_args_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ConstructRecordArgsDictFromRecordID</span><span class="p">(</span>
              <span class="n">record</span><span class="p">[</span><span class="s">&#39;records_id&#39;</span><span class="p">])</span>

          <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ProcessRecordsBatch&#39;</span><span class="p">,</span>
              <span class="n">record_data</span> <span class="o">=</span> <span class="p">{</span>
                  <span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">],</span>
                  <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">],</span>
                  <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">record_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">],</span>
                  <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">],</span>
                  <span class="s">&#39;record_args_dict&#39;</span><span class="p">:</span> <span class="n">record_args_dict</span><span class="p">},</span>
              <span class="n">current_transaction</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

          <span class="n">rows_deleted</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">RemoveRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">record_dict</span><span class="p">)</span>
          <span class="n">log_dict</span><span class="p">[</span><span class="s">&#39;delete&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
          <span class="n">row_count</span> <span class="o">+=</span> <span class="mi">1</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">rows_deleted</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="p">):</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordsBatchError</span><span class="p">(</span>
                  <span class="s">&#39;Record specification too broad, &#39;</span>
                  <span class="s">&#39;found </span><span class="si">%d</span><span class="s"> matching records for </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                      <span class="n">rows_deleted</span><span class="p">,</span> <span class="n">record_dict</span><span class="p">))</span>
          <span class="k">elif</span><span class="p">(</span> <span class="n">rows_deleted</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordsBatchError</span><span class="p">(</span>
                  <span class="s">&#39;No record found for :</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">record_dict</span><span class="p">)</span>

        <span class="c"># ADD RECORDS</span>
        <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">add_records</span><span class="p">:</span>

          <span class="c">#Target length check</span>
          <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">data_validation_instance</span><span class="o">.</span><span class="n">isTarget</span><span class="p">(</span>
              <span class="n">record</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">])</span> <span class="p">):</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">InvalidInputError</span><span class="p">(</span><span class="s">&#39;Target hostname is invalid. </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span>
                <span class="n">record</span><span class="p">[</span><span class="s">u&#39;record_target&#39;</span><span class="p">]))</span>

          <span class="n">view_name</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span>
          <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&#39;_dep&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">record</span><span class="p">[</span>
                <span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="s">u&#39;any&#39;</span><span class="p">):</span>
            <span class="n">view_name</span> <span class="o">=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">_dep&#39;</span> <span class="o">%</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">]</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">Authorize</span><span class="p">(</span><span class="s">&#39;ProcessRecordsBatch&#39;</span><span class="p">,</span>
              <span class="n">record_data</span> <span class="o">=</span> <span class="p">{</span>
                  <span class="s">&#39;target&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">],</span>
                  <span class="s">&#39;zone_name&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">],</span>
                  <span class="s">&#39;view_name&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
                  <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">],</span>
                  <span class="s">&#39;record_args_dict&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">]},</span>
              <span class="n">current_transaction</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">u&#39;ptr&#39;</span> <span class="p">):</span>
            <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">][</span>
                <span class="s">&#39;assignment_host&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;@.&#39;</span><span class="p">)</span> <span class="p">):</span>
              <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">][</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span>
                  <span class="s">&#39;record_arguments&#39;</span><span class="p">][</span><span class="s">&#39;assignment_host&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s">&#39;@.&#39;</span><span class="p">)</span>
          <span class="n">changed_view_dep</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">view_name</span><span class="p">,</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">]))</span>
          <span class="n">ttl</span> <span class="o">=</span> <span class="bp">None</span>
          <span class="k">if</span><span class="p">(</span> <span class="s">&#39;ttl&#39;</span> <span class="ow">in</span> <span class="n">record</span> <span class="p">):</span>
            <span class="n">ttl</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">]</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">ttl</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
            <span class="n">ttl</span> <span class="o">=</span> <span class="n">constants</span><span class="o">.</span><span class="n">DEFAULT_TTL</span>

          <span class="n">records_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;records_id&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                          <span class="s">&#39;record_target&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">],</span>
                          <span class="s">&#39;record_type&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                          <span class="s">&#39;record_ttl&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
                          <span class="s">&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">],</span>
                          <span class="s">&#39;record_view_dependency&#39;</span><span class="p">:</span> <span class="n">view_name</span><span class="p">,</span>
                          <span class="s">&#39;record_last_user&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">}</span>

          <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;cname&#39;</span> <span class="p">):</span>
            <span class="n">all_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
            <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_records</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
              <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordsBatchError</span><span class="p">(</span>
                  <span class="s">&#39;Record already exists with target </span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span>
                  <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]))</span>
          <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s">u&#39;cname&#39;</span>
          <span class="n">cname_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
          <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">cname_records</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="p">):</span>
            <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordsBatchError</span><span class="p">(</span><span class="s">&#39;CNAME already exists with target &#39;</span>
                                           <span class="s">&#39;</span><span class="si">%s</span><span class="s">.&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">]))</span>

          <span class="n">record_args_assignment_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">GetEmptyRowDict</span><span class="p">(</span>
              <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">)</span>
          <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span>
          <span class="n">raw_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">ListRow</span><span class="p">(</span>
              <span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">,</span> <span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
              <span class="n">record_args_assignment_dict</span><span class="p">)</span>
          <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_last_user&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">GetUserName</span><span class="p">()</span>
          <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_ttl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ttl</span>
          <span class="n">current_records</span> <span class="o">=</span> <span class="p">(</span>
              <span class="n">helpers_lib</span><span class="o">.</span><span class="n">GetRecordsFromRecordRowsAndArgumentRows</span><span class="p">(</span>
              <span class="n">raw_records</span><span class="p">,</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">]))</span>
          <span class="k">for</span> <span class="n">current_record</span> <span class="ow">in</span> <span class="n">current_records</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">arg</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">current_record</span> <span class="p">):</span>
                <span class="k">break</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">][</span><span class="n">arg</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="p">):</span>
                <span class="k">continue</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">][</span><span class="n">arg</span><span class="p">]</span> <span class="o">!=</span> <span class="n">current_record</span><span class="p">[</span><span class="n">arg</span><span class="p">]</span> <span class="p">):</span>
                <span class="k">break</span>
            <span class="k">else</span><span class="p">:</span>
              <span class="k">raise</span> <span class="n">errors</span><span class="o">.</span><span class="n">RecordsBatchError</span><span class="p">(</span><span class="s">&#39;Duplicate record found: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span>
                                             <span class="n">current_record</span><span class="p">)</span>


          <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span>
          <span class="n">record_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;records&#39;</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">)</span>
          <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">record_argument_assignments_dict</span> <span class="o">=</span> <span class="p">{</span>
               <span class="s">&#39;record_arguments_records_assignments_record_id&#39;</span><span class="p">:</span> <span class="n">record_id</span><span class="p">,</span>
               <span class="s">&#39;record_arguments_records_assignments_type&#39;</span><span class="p">:</span> <span class="n">record</span><span class="p">[</span>
                   <span class="s">&#39;record_type&#39;</span><span class="p">],</span>
               <span class="s">&#39;record_arguments_records_assignments_argument_name&#39;</span><span class="p">:</span> <span class="n">arg</span><span class="p">,</span>
               <span class="s">&#39;argument_value&#39;</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">][</span><span class="n">arg</span><span class="p">])}</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">MakeRow</span><span class="p">(</span><span class="s">&#39;record_arguments_records_assignments&#39;</span><span class="p">,</span>
                                     <span class="n">record_argument_assignments_dict</span><span class="p">)</span>
            <span class="n">log_dict</span><span class="p">[</span><span class="s">&#39;add&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
            <span class="n">row_count</span> <span class="o">+=</span> <span class="mi">1</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">]</span> <span class="ow">in</span>
              <span class="n">constants</span><span class="o">.</span><span class="n">RECORD_TYPES_INDEXED_BY_IP</span> <span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">_AddRecordToIpIndex</span><span class="p">(</span>
                <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_type&#39;</span><span class="p">],</span> <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_zone_name&#39;</span><span class="p">],</span>
                <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_view_dependency&#39;</span><span class="p">],</span>
                <span class="n">record_id</span><span class="p">,</span> <span class="n">records_dict</span><span class="p">[</span><span class="s">&#39;record_target&#39;</span><span class="p">],</span>
                <span class="n">record</span><span class="p">[</span><span class="s">&#39;record_arguments&#39;</span><span class="p">])</span>
        <span class="n">changed_view_dep</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">changed_view_dep</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">view_dep_pair</span> <span class="ow">in</span> <span class="n">changed_view_dep</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">core_instance</span><span class="o">.</span><span class="n">_IncrementSoa</span><span class="p">(</span><span class="o">*</span><span class="n">view_dep_pair</span><span class="p">,</span> <span class="n">missing_ok</span><span class="o">=</span><span class="n">zone_import</span><span class="p">)</span>

      <span class="k">except</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">raise</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">db_instance</span><span class="o">.</span><span class="n">EndTransaction</span><span class="p">()</span>
      <span class="n">success</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">finally</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">log_instance</span><span class="o">.</span><span class="n">LogAction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user_instance</span><span class="o">.</span><span class="n">user_name</span><span class="p">,</span> <span class="n">function_name</span><span class="p">,</span>
                                  <span class="n">current_args</span><span class="p">,</span> <span class="n">success</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">row_count</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListSortedHostsByZone"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListSortedHostsByZone">[docs]</a>  <span class="k">def</span> <span class="nf">ListSortedHostsByZone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ListRecordsByZone</span><span class="p">(</span><span class="n">zone_name</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="n">view_name</span><span class="p">)</span>
    <span class="n">sorted_records</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">SortRecordsByHost</span><span class="p">(</span><span class="n">records_dict</span><span class="p">)</span>
    <span class="n">hosts_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">sorted_records</span><span class="p">:</span>
      <span class="n">direction</span> <span class="o">=</span> <span class="s">&#39;Reverse&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;forward&#39;</span><span class="p">]</span> <span class="p">):</span>
        <span class="n">direction</span> <span class="o">=</span> <span class="s">&#39;Forward&#39;</span>
      <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">hosts_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">record</span><span class="p">[</span><span class="s">u&#39;view_name&#39;</span><span class="p">])</span> <span class="p">):</span>
        <span class="n">hosts_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">record</span><span class="p">[</span><span class="s">u&#39;view_name&#39;</span><span class="p">]:</span> <span class="p">[]})</span>
      <span class="n">new_record</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
      <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;direction&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">direction</span>
      <span class="n">hosts_dict</span><span class="p">[</span><span class="n">record</span><span class="p">[</span><span class="s">u&#39;view_name&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_record</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">hosts_dict</span>
</div>
<div class="viewcode-block" id="CoreHelpers.ListSortedHostsByCIDR"><a class="viewcode-back" href="../../roster_core.html#roster_core.core_helpers.CoreHelpers.ListSortedHostsByCIDR">[docs]</a>  <span class="k">def</span> <span class="nf">ListSortedHostsByCIDR</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cidr</span><span class="p">,</span> <span class="n">zone_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">view_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="n">records_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ListRecordsByCIDRBlock</span><span class="p">(</span><span class="n">cidr</span><span class="p">,</span> <span class="n">zone_name</span><span class="o">=</span><span class="n">zone_name</span><span class="p">,</span> 
      <span class="n">view_name</span><span class="o">=</span><span class="n">view_name</span><span class="p">)</span>
    <span class="n">ip_address_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">CIDRExpand</span><span class="p">(</span><span class="n">cidr</span><span class="p">)</span>
    
    <span class="k">if</span> <span class="n">ip_address_list</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
      <span class="n">ip_address_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">if</span><span class="p">(</span> <span class="n">ip_address_list</span> <span class="o">==</span> <span class="p">[]</span> <span class="p">):</span>
      <span class="k">for</span> <span class="n">view</span> <span class="ow">in</span> <span class="n">records_dict</span><span class="p">:</span>
        <span class="n">ip_address_list</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">records_dict</span><span class="p">[</span><span class="n">view</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
      <span class="n">ip_address_list</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">ip_address_list</span><span class="p">))</span>

    <span class="n">hosts_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">if</span><span class="p">(</span> <span class="nb">len</span><span class="p">(</span><span class="n">records_dict</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">):</span>
      <span class="n">hosts_dict</span><span class="p">[</span><span class="s">&#39;--&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
      <span class="k">for</span> <span class="n">ip_address</span> <span class="ow">in</span> <span class="n">ip_address_list</span><span class="p">:</span>
        <span class="n">hosts_dict</span><span class="p">[</span><span class="s">&#39;--&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
            <span class="p">{</span><span class="s">&#39;host&#39;</span><span class="p">:</span> <span class="s">&#39;--&#39;</span><span class="p">,</span> <span class="s">&#39;direction&#39;</span><span class="p">:</span> <span class="s">&#39;--&#39;</span><span class="p">,</span>
             <span class="s">&#39;ip_address&#39;</span><span class="p">:</span> <span class="n">ip_address</span><span class="p">,</span> <span class="s">&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="s">&#39;--&#39;</span><span class="p">})</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">for</span> <span class="n">view</span> <span class="ow">in</span> <span class="n">records_dict</span><span class="p">:</span>
        <span class="k">if</span><span class="p">(</span> <span class="ow">not</span> <span class="n">hosts_dict</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">view</span><span class="p">)</span> <span class="p">):</span>
          <span class="n">hosts_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">view</span><span class="p">:</span> <span class="p">[]})</span>
        <span class="k">for</span> <span class="n">ip_address</span> <span class="ow">in</span> <span class="n">ip_address_list</span><span class="p">:</span>
          <span class="k">if</span><span class="p">(</span> <span class="n">ip_address</span> <span class="ow">in</span> <span class="n">records_dict</span><span class="p">[</span><span class="n">view</span><span class="p">]</span> <span class="p">):</span>
            <span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records_dict</span><span class="p">[</span><span class="n">view</span><span class="p">][</span><span class="n">ip_address</span><span class="p">]:</span>
              <span class="n">direction</span> <span class="o">=</span> <span class="s">&#39;Reverse&#39;</span>
              <span class="k">if</span><span class="p">(</span> <span class="n">record</span><span class="p">[</span><span class="s">&#39;forward&#39;</span><span class="p">]</span> <span class="p">):</span>
                <span class="n">direction</span> <span class="o">=</span> <span class="s">&#39;Forward&#39;</span>
              <span class="n">new_record</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
              <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;direction&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">direction</span>
              <span class="n">new_record</span><span class="p">[</span><span class="s">&#39;ip_address&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ip_address</span>
              <span class="n">hosts_dict</span><span class="p">[</span><span class="n">view</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_record</span><span class="p">)</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="n">hosts_dict</span><span class="p">[</span><span class="n">view</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">{</span><span class="s">&#39;ip_address&#39;</span><span class="p">:</span> <span class="n">ip_address</span><span class="p">,</span> <span class="s">&#39;direction&#39;</span><span class="p">:</span> <span class="s">&#39;--&#39;</span><span class="p">,</span> <span class="s">&#39;host&#39;</span><span class="p">:</span> <span class="s">&#39;--&#39;</span><span class="p">,</span>
                 <span class="s">&#39;record_zone_name&#39;</span><span class="p">:</span> <span class="s">&#39;--&#39;</span><span class="p">})</span>
    <span class="k">return</span> <span class="n">hosts_dict</span>
<span class="c"># vi: set ai aw sw=2:</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">Roster Core v0.17 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Purdue University.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>